!(function () {

  let evn = null

  wx.miniProgram.getEnv(function (res) {
    // console.log(res.miniprogram) // true
    console.log(res);
    evn = res;
  })

  window.wxutil = {
    isMiniProgram() {
      return evn && evn.miniprogram
    },
    navigateTo(opts) {
      if (this.isMiniProgram()) {
        wx.miniProgram.navigateTo(opts)
      }
    },
    navigateBack(delta = 1) {
      if (this.isMiniProgram()) {
        wx.miniProgram.navigateBack({
          delta: delta
        })
      }
    },
    postMessage(data) {
      if (this.isMiniProgram() && wx.miniProgram.postMessage) {
        wx.miniProgram.postMessage(data)
      }
    },
    getLocation(opts) {
      // if (this.isMiniProgram()) {
      wx.getLocation(opts)
      // }
    },
    chooseImage(opts) {
      wx.chooseImage(opts)
    }
  }

})();